package com.chezhujie.www.controller;

import com.chezhujie.www.domain.Czjawardstock;
import com.chezhujie.www.domain.Czjawarduse;
import com.chezhujie.www.enums.OrderStatus;
import com.chezhujie.www.service.*;
import com.chezhujie.www.utils.UUIDUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 单元测试工具
 * @author 汤伟杰
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:springmvc-mybatis.xml"})
public class ReadDaoImplTest extends BaseController{

	private static Integer userinfoId = 213523;//汤伟杰
	private static Integer userinfoId2 = 213519;//周冰
	private static String idCard = "440782199201125017";
	private static String objectId = "";
	private static Integer count = 2;
	private static Integer objectType = 1;
	private static String distributionId = "";
	private static String remarks = "";
	private static Integer total_fee = 1;//费用0.01
	private static String wxOrderNo = "wx"+ UUIDUtils.getDateUUID();
	private static String orderNo = "2017062233845447207";
	private static String openid = "oRYMns_SBJTs5-FQREG3aACMSE-Q";
	private static String timeend = "20170620182100";

	private static String actId= "1dLQ22bMqHRwywxUlLv";//彩色跑Id
	private static String commodityId = "2FI0NBU4QnaYKtszNjO";//大中华
	private static String commodityId4 = "25gKg1oRiKc2LLTsNwB";//测试商品名字
	private static String couponsId = "JgUcEuICui5S5TZSAkm";//大中华 优惠券1块
	private static String couponsId2 = "TmekWJdkj05aah090mA";//彩色跑 优惠券1块
	private static String couponsId3 = "M9Z4oWKCTZMfTy2nEjV";//大中华 优惠券1块
	private static String couponsId4 = "M9Z4oWKCTZMfTy2nEjV";//大中华 优惠券1块



    @Test
    public void doMain() throws Exception {
//		addCommodityCoupons();
//		addAct();
//		genernate();
//		weixininfoService.sendredpack(null,null,null);
		/*Czjrefund czjrefund  = new Czjrefund();
		czjrefund.setRefundId("oAo96WRP8NFrVxjseyf");
		System.out.println(czjrefund.getRefundId());
		czjrefund.setCreatetime(new Date());
		czjrefund.setDelFlag(0);
		czjrefund.setRefundStatus(1);
		czjrefund.setOrderCode("23423");
		czjrefund.setUserinfoId(43213);
		czjrefund.setBusinessId("1");
		czjrefund.setRefundAmount(new BigDecimal(55));
		czjrefund.setUpdatetime(new Date());

		czjrefundService.insert(czjrefund);*/

//		Czjrefund czjrefund = czjrefundService.queryById("oAo96WRP8NFrVxjseyf");
//		czjrefund.setUpdatetime(new Date());
//		czjrefundService.update(czjrefund);

		/*String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>  \n<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[IP地址非你在商户平台设置的可用IP地址]]></return_msg><result_code><![CDATA[FAIL]]></result_code><err_code><![CDATA[NO_AUTH]]></err_code><err_code_des><![CDATA[IP地址非你在商户平台设置的可用IP地址]]></err_code_des><mch_billno><![CDATA[1366381802201718202135239983]]></mch_billno><mch_id><![CDATA[1366381802]]></mch_id><wxappid><![CDATA[wx5e3453d525417756]]></wxappid><re_openid><![CDATA[olUDTwh2w4YTIps-vQCBYVnyRBrM]]></re_openid><total_amount>100</total_amount></xml>";
		Document document = DocumentHelper.parseText(xml);
		Map<String, String> map = Dom4jUtils.Dom2Map(document);
		System.out.println(map.get("return_code"));
		if("SUCCESS".equals(map.get("return_code"))){
			if("FAIL".equals(map.get("result_code"))){
				System.out.println(map.get("err_code_des"));
			}else{

			}
		}else{
			System.out.println("失败2");
		}*/
//		czjrefundService.
//		String json = "{\"sex\":2,\"nickname\":\"long for home维嘉<U+1F444>\\xF0\\x9F\\x91\\x84\",\"privilege\":[],\"province\":\"广东\",\"openid\":\"olUDTwia1Tdf5x812bs1wogMfp8c\",\"language\":\"zh_CN\",\"headimgurl\":\"http://wx.\n" +
//				"qlogo.cn/mmopen/UbfuJTh4VWRtLkz70HtLFMqeVueZXWjE8h7vk059Nf6V9wFGSkhkCoZkaLZRcuFBicXiba7QuNsM0howG6ibfYTczle67BXuPbN/0\",\"country\":\"中国\",\"city\":\"东莞\"}\n";
//		WeixinInfo weixininfo = JSONObject.parseObject(json, WeixinInfo.class);
//
//
//
//		String nickname =weixininfo.getNickname();
////		nickname = nickname.replaceAll("[\ue000-\uefff]", "");
//
//		System.out.println(nickname);
////		weixininfoService.saveWeixin(weixininfo);
//		Czjawardstock czjawardstock = new Czjawardstock();
//		czjawardstock.setThingName(nickname);
////		nickname = nickname.replace("<","&lt;");
////		nickname = nickname.replace(">","&gt;");
//		czjawardstock.setThingName(nickname);
//
//		czjawardstockService.insertCzjawardstock(czjawardstock);


		czjusecouponService.businessSave("oiLtyZNVLU9i8AJr0N8","1");





		System.out.println("成功");
	}



	public static void main(String[] args) {
//		genernate();

	}
//	http://localhost:8080/chezhujie/api1/generateOrder.jn?userinfoId=213523&count=2&objectId=2FI0NBU4QnaYKtszNjO&
	public static void genernate(){
		String url = "http://localhost:8080/chezhujie/api1/generateOrder.jn";
		Map<String, String> params = new HashMap<String, String>();
		params.put("userinfoId", String.valueOf(userinfoId));
		params.put("count", String.valueOf(count));
		params.put("objectId", commodityId);
//		params.put("couponsId", couponsId);
		String uri = url;
		int i = 0;
		for (Map.Entry<String, String> entry : params.entrySet()) {
			if (i == 0) {
				uri += "?" + entry.getKey() + "=" + entry.getValue() + "&";
			} else {
				uri += entry.getKey() + "=" + entry.getValue() + "&";
			}
			if (i == params.size()) {
				uri = uri.substring(0, uri.length() - 1);
			}
			i++;
		}
		System.out.println(uri+"&distributionId=5lONgMlH4y9D5iDTvLs");
//		Map<String, Object> data = CommonHttp.send(url, "get", params);
		System.out.println("==================返回结果==================");
		System.out.println(uri);
//		System.out.println(ForMatJSONStr.format(JSONObject.toJSONString(data)));
		System.out.println("==================结束==================");

	}
    public void addCommodityCoupons(){
//新增优惠券//关联商家或者关联活动
		try{
			Czjawarduse czjawarduse = new Czjawarduse();
			Czjawardstock czjawardstock = new Czjawardstock();

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			czjawardstock.setThingName("优惠1元");
			czjawardstock.setContent("大中华优惠券，能抵消10元");
			czjawardstock.setValidDate(sdf.parse("2017-07-10 13:45:00"));
			czjawardstock.setExt3("25gKg1oRiKc2LLTsNwB");
			czjawardstock.setAwardstockId(UUIDUtils.getUUID());
			czjawardstock.setAwardType(2);
			czjawardstock.setPrice(new BigDecimal(10));
			czjawardstockService.insertCzjawardstock(czjawardstock);
			czjawarduse.setUserInfoId(String.valueOf(userinfoId2));
			czjawarduse.setAwarduseId(UUIDUtils.getUUID());
			czjawarduse.setAwardId(czjawardstock.getAwardstockId());
			czjawarduse.setStatus(OrderStatus.UNUSE.getIndex());
			czjawarduse.setPrice(czjawardstock.getPrice());
			czjawarduse.setCreatetime(new Date());
			czjawarduseService.insertCzjawarduse(czjawarduse);
			System.out.println("优惠券id:"+czjawarduse.getAwarduseId());
		}catch (Exception e){
			e.printStackTrace();

		}
	}
	public void addAct(){
//新增优惠券//关联商家或者关联活动
		try{
			Czjawarduse czjawarduse = new Czjawarduse();
			Czjawardstock czjawardstock = new Czjawardstock();

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			czjawardstock.setThingName("优惠1元");
			czjawardstock.setContent("大中华优惠券，能抵消0.04元");
			czjawardstock.setValidDate(sdf.parse("2017-07-11 15:00:00"));
			czjawardstock.setExt2("13YWda0yfkKvW2cOzyH");//活动id
			czjawardstock.setAwardstockId(UUIDUtils.getUUID());
			czjawardstock.setPrice(new BigDecimal(0.04));
			czjawardstock.setAwardType(2);
			czjawardstockService.insertCzjawardstock(czjawardstock);
			czjawarduse.setUserInfoId(String.valueOf(userinfoId2));
			czjawarduse.setAwarduseId(UUIDUtils.getUUID());
			czjawarduse.setAwardId(czjawardstock.getAwardstockId());
			czjawarduse.setStatus(OrderStatus.UNUSE.getIndex());
			czjawarduse.setPrice(czjawardstock.getPrice());
			czjawarduseService.insertCzjawarduse(czjawarduse);
			System.out.println("优惠券id:"+czjawarduse.getAwarduseId());
		}catch (Exception e){
			e.printStackTrace();

		}
	}


	@Autowired
	private Czjcommodity3Service czjcommodity3Service;
	@Autowired
	private ApitwjService apitwjService;
	@Autowired
	private CzjreplyService czjreplyService;
	@Autowired
	private CzjcommentsService czjcommentsService;
	@Autowired
	private CzjcommodityService czjcommodityService;
	@Autowired
	private CzjorderdetailService czjorderdetailService;
	@Autowired
	private CzjorderService czjorderService;
	@Autowired
	private CzjorderdistributionService czjorderdistributionService;
	@Autowired
	private CzjdeliveryaddService czjdeliveryaddService;
	@Autowired
	private CzjactivityService czjactivityService;
	@Autowired
	private CzjfestivalactService czjfestivalactService;
	@Autowired
	private CzjdataresourceService czjdataresourceService;
	@Autowired
	private CzjactdetailService czjactdetailService;
	@Autowired
	private CzjtordermemberService czjtordermemberService;
	@Autowired
	private CzjtordermemberdetailService czjtordermemberdetailService;
	@Autowired
	private CzjmemberService czjmemberService;
	@Autowired
	private CzjusermessService czjusermessService;
	@Autowired
	private CzjawardstockService czjawardstockService;
	@Autowired
	private CzjawarduseService czjawarduseService;
	@Autowired
	private WeixininfoService weixininfoService;
	@Autowired
	private CzjrefundService czjrefundService;
	@Autowired
	private CzjusecouponService czjusecouponService;

}
